<?php
Yii::import('application.components.login.class.LoginAuth');
Yii::import('application.components.login.class.LoginIdentity');
class AnonyAuth extends LoginAuth{  //20150716 sxw 通过邮件找回
	public $id;
	
	public function rules()
	{
		return array(
				// username and password are required
				array('id', 'required'),
				array('id','loginExist'),
		);
	}
	
	public function loginExist($attribute,$params){
		$customer = new Customer();
		$customer = $customer->findByAttributes(array('id' => $this->id, 'status' => 1));
		if (!empty($customer)){
			$this->setPrimary($customer->id);
			$this->setUsername($customer->user_name);
		}else{
			$this->addError($attribute,'验证无效或该用户不存在');
		}
	}
	
	public function authenticate(){
		$valid = $this->valid();
		if ($valid) {
			$this->setPrimary($this->id);
			$this->setUsername($this->username);
		}
		return $valid;
	}
	
	
}